﻿using AppFramework;
using AppFramework.Admin.ViewModels;
using AppFramework.ApiClient;
using AppFramework.Authorization.Users.Profile.Dto;
using AppFramework.DinosaursParkMes.Production.DTO;
using AppFramework.DinosaursParkMes.UniqueIdCode;
using AppFramework.DinosaursParkMes.UniqueIdCode.Dto;
using AppFramework.DinosaursParkMes.Execute;
using AppFramework.DinosaursParkMes.Execute.Dto;
using AppFramework.Shared;
using AppFramework.DynamicEntityProperties;
using System.Windows.Threading;
using AppFramework.Shared.Services;
using Models.DinosaursParkMes.Production;
using Models.DinosaursParkMes.UniqueIdCode;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Media.Media3D;
using System.Xml.Linq;
using AppFramework.Demo;
using AppFramework.Version.Dtos;
using Prism.Mvvm;
using System.Windows;
using System.Threading.Tasks;

namespace ViewModels.DinosaursParkMes.UniqueIdCode
{
    public class UniqueIdCodelViewModel : NavigationCurdViewModel
    {
        private readonly IUniqueIdCodeAppService uniqueIdCodeAppService;
        public UniqueIdCodeRequisition uniqueIdCodeRequisition;
        public List<BarcodeStandardlist> barcodeStandardlist;
        public List<Barcodetypelist> barcodetypelists;
        public UniqueIdCodelViewModel(IUniqueIdCodeAppService uniqueIdCodeAppService, UniqueIdCodeRequisition uniqueIdCodeRequisitio=null, List<BarcodeStandardlist> barcodeStandardlist=null, List<Barcodetypelist> barcodetypelists=null)
        {
            this.uniqueIdCodeAppService = uniqueIdCodeAppService;
            this.uniqueIdCodeRequisition = new UniqueIdCodeRequisition ();
            this.barcodeStandardlist = barcodeStandardlist;
            this.barcodetypelists = new List<Barcodetypelist>();
            ShowCommand = new MyConnand(Show);
            AddCommand = new MyConnand(add);
        }
        public MyConnand ShowCommand { get; set; }
        public MyConnand AddCommand { get; set; }

        public List<Barcodetypelist> Barcodetypelist
        {
            get { return barcodetypelists; }
            set { barcodetypelists = value; OnPropertyChanged(); }
        }
        public UniqueIdCodeRequisition Models
        {
            get { return uniqueIdCodeRequisition; }
            set { uniqueIdCodeRequisition = value; OnPropertyChanged(); }
        }
        public void Show()
        {
            MessageBox.Show("添加成功");
        }
        public async void add()
        {
            await SetBusyAsync(async () =>
            {
                var dto = Map<UniqueIdCodeAddDTO>(Models);
                await uniqueIdCodeAppService.UniqueIdCodeAdd(dto);
            });
        }
        //条码格式下拉
        private async Task GetExecutes()
        {
            await SetBusyAsync(async () =>
            {
                await uniqueIdCodeAppService.BarcodeStandard().WebAsync(dataPager.SetList);
            });
        }
        //条码类型下拉
        private async Task GetBarcodetype()
        {
            await SetBusyAsync(async () =>
            {
                Barcodetypelist = await uniqueIdCodeAppService.GetBarcodetype();
            });
        }
        public override async Task OnNavigatedToAsync(NavigationContext navigationContext = null)
        {
            await SetBusyAsync(async () =>
            {
                await GetExecutes();
                await GetBarcodetype();
            });
        }

    }
}
